package cn.lingyangwl.framework.oss.config;

import cn.lingyangwl.framework.storage.base.config.AliyunStorageProperties;
import cn.lingyangwl.framework.storage.base.config.StorageProperties;
import cn.lingyangwl.framework.storage.base.constants.FileStorageEnum;
import cn.lingyangwl.framework.storage.base.manager.BaseStorageManager;
import cn.lingyangwl.framework.storage.base.manager.StorageManager;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * Description:
 *
 * @author shenguangyang
 */
@Slf4j
public class AliyunOssConfig {
    @Resource
    StorageProperties storageProperties;

    @Resource
    AliyunStorageProperties aliyunStorageProperties;

    @PostConstruct
    public void init() throws Exception {
        if (!storageProperties.getInitClient()) {
            return;
        }
        FileStorageEnum type = storageProperties.getStorage();
        if (type == FileStorageEnum.ALIYUN || type == FileStorageEnum.ALL) {
            StorageManager storageManager = BaseStorageManager.get(FileStorageEnum.ALIYUN);
            storageManager.createClient(aliyunStorageProperties.getAccessKeyId(), aliyunStorageProperties.getSecretAccessKey());
        }
    }
}
